package database;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

public class MyConnection {

    private static MyConnection myconn = null;
    Connection con = null;

    public static MyConnection getInstance() {
        if (myconn == null) {
            myconn = new MyConnection();
        }
        return myconn;
    }

    public MyConnection() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://" + "145.100.98.58" + ":" + "3306" + "/" + "openinternetnew", "root", "ISOC8*o0");
        } catch (Exception ex) {
            Logger.getLogger(MyConnection.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public Connection getConnection() throws Exception {
        return con;
    }

    public static void close(Connection o) {
        /*
         try {
         if (o != null) {
         o.close();
         }
         } catch (Exception ex) {
         ex.printStackTrace();
         }*/
    }

    public static void close(Statement o) {
        try {
            if (o != null) {
                o.close();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public static void close(ResultSet o) {
        try {
            if (o != null) {
                o.close();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
